<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace xsl\basic;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface as Psr7ResponseInterface;
use xsl\enums\Code;

abstract class BaseController
{
    #[Inject]
    protected ContainerInterface $container;

    #[Inject]
    protected RequestInterface $request;

    #[Inject]
    protected ResponseInterface $response;

    public function pageSuccess(mixed $limit = 10, mixed $total = 0, mixed $data = [], string $message = '操作成功', int $code = Code::SUCCESS): Psr7ResponseInterface
    {
        return $this->response->json([
            'code' => $code,
            'message' => $message,
            'data' => $data,
            'limit' => $limit,
            'total' => $total,
        ]);
    }

    public function success(mixed $data = [], string $message = '操作成功', int $code = Code::SUCCESS): Psr7ResponseInterface
    {
        return $this->response->json([
            'code' => $code,
            'message' => $message,
            'data' => $data,
        ]);
    }

    public function error(string $message = '操作失败', int $code = Code::SUCCESS): Psr7ResponseInterface
    {
        return $this->response->json([
            'code' => $code,
            'message' => $message,
        ]);
    }
}
